package util;

import java.io.InputStream;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import session.AdminFacadeRemote;
import session.DefectlogFacadeRemote;
import session.EmployeeFacadeRemote;
import session.EmployeeprojectFacadeRemote;
import session.LogstatusFacadeRemote;
import session.LogtypeFacadeRemote;
import session.PositionFacadeRemote;
import session.PriorityFacadeRemote;
import session.ProjectFacadeRemote;
import session.ProjectstatusFacadeRemote;
import session.SeverityFacadeRemote;

/**
 *
 * @author HuyNVK
 */
public class Facade {
//    private static Properties props = new Properties();
    
//    static {
//        try {
//            InputStream is = Facade.class.getResourceAsStream("/jndi.properties");           
//            props.load(is);	
//        } catch (Exception ex) {
//            
//        }
//    }
    
    public static InitialContext getInitialContext() throws NamingException {
        Properties props = new Properties();

        props.setProperty("java.naming.factory.initial",
                "com.sun.enterprise.naming.SerialInitContextFactory");

        props.setProperty("java.naming.factory.url.pkgs",
                "com.sun.enterprise.naming");

        props.setProperty("java.naming.factory.state",
                "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
        props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");

        // optional.  Defaults to 3700.  Only needed if target orb port is not 3700.
        props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
        
        return new InitialContext(props);
    }
    
    public static AdminFacadeRemote getAdminFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/AdminFacade");
        return (AdminFacadeRemote) ref;
    }
    
    public static DefectlogFacadeRemote getDefectLogFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/DefectlogFacade");
        return (DefectlogFacadeRemote) ref;
    }
    
    public static EmployeeFacadeRemote getEmployeeFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/EmployeeFacade");
        return (EmployeeFacadeRemote) ref;
    }
    
    public static EmployeeprojectFacadeRemote getEmployeeProjectFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/EmployeeprojectFacade");
        return (EmployeeprojectFacadeRemote) ref;
    }
    
    public static LogstatusFacadeRemote getLogStatusFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/LogstatusFacade");
        return (LogstatusFacadeRemote) ref;
    }
    
    public static LogtypeFacadeRemote getLogTypeFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/LogtypeFacade");
        return (LogtypeFacadeRemote) ref;
    }
    
    public static PositionFacadeRemote getPositionFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/PositionFacade");
        return (PositionFacadeRemote) ref;
    }
    
    public static PriorityFacadeRemote getPriorityFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/PriorityFacade");
        return (PriorityFacadeRemote) ref;
    }
    
    public static ProjectFacadeRemote getProjectFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/ProjectFacade");
        return (ProjectFacadeRemote) ref;
    }
    
    public static ProjectstatusFacadeRemote getProjectStatusFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/ProjectstatusFacade");
        return (ProjectstatusFacadeRemote) ref;
    }
    
    public static SeverityFacadeRemote getSeverityFacade() throws NamingException {
        Object ref = getInitialContext().lookup("java:global/ejb-serv/SeverityFacade");
        return (SeverityFacadeRemote) ref;
    }
}
